/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.im.api.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.im.api.bean.AddressData;
import com.im.api.bean.ServerAddress;
import com.only.common.result.ResultMessage;
import com.only.common.util.OnlyPropertiesUtil;
import com.only.general.annotation.parameter.RequestParameter;

/**
 *
 * @author Only
 */
@Controller
@RequestMapping("/api/v1/oim/server")
public class ServerController {

	/**
	 * data={userData:{}}
	 * 
	 * @author: XiaHui
	 * @createDate: 2016年11月22日 上午9:45:09
	 * @update: XiaHui
	 * @updateDate: 2016年11月22日 上午9:45:09
	 */
	@CrossOrigin
	@ResponseBody
	@RequestParameter
	@RequestMapping(method = RequestMethod.POST, value = "/address")
	public Object address(HttpServletRequest request) {
		ResultMessage rm = new ResultMessage();

		String mainAddress = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "main.server.address");
		String mainPort = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "main.server.port");
		String remoteAddress = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "remote.server.address");
		String remotePort = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "remote.server.port");

		AddressData mainServerAddressData = new AddressData();
		mainServerAddressData.setAddress(mainAddress);
		mainServerAddressData.setPort(Integer.parseInt(mainPort));

		AddressData remoteServerAddressData = new AddressData();
		remoteServerAddressData.setAddress(remoteAddress);
		remoteServerAddressData.setPort(Integer.parseInt(remotePort));

		String fileOfflineServerURL = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "file.server.url");
		String userServerURL = OnlyPropertiesUtil.getProperty("config/setting/server.properties", "file.server.url");

		ServerAddress serverAddress = new ServerAddress();
		serverAddress.setMainServerAddressData(mainServerAddressData);
		serverAddress.setRemoteServerAddressData(remoteServerAddressData);
		serverAddress.setFileOfflineServerURL(fileOfflineServerURL);
		serverAddress.setUserServerURL(userServerURL);
		rm.put("serverAddress", serverAddress);
		return rm;
	}
}
